package com.jinshan.edu.controller;


import com.jinshan.edu.entity.EduSection;
import com.jinshan.edu.service.EduSectionService;
import com.jinshan.response.RetVal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 课程小节 前端控制器
 * </p>
 *
 * @author Jinshan
 * @since 2020-06-27
 */
@RestController
@RequestMapping("/edu/section")
@CrossOrigin
public class EduSectionController {
    @Autowired
    private EduSectionService sectionService;

    @PostMapping("/saveSection")
    public RetVal saveSection(EduSection eduSection) {
        sectionService.saveSection(eduSection);
        return RetVal.success();
    }

    @DeleteMapping("/{id}")
    public RetVal deleteSectionById(@PathVariable String id) {
        boolean flag =  sectionService.deleteSectionById(id);
        if (flag) {
            return RetVal.success().message("删除小节成功");
        } else {
            return RetVal.error().message("删除小节失败");
        }
    }

    @PutMapping("/updateSection")
    public RetVal updateSection(EduSection section) {
        sectionService.updateSection(section);
        return RetVal.success();
    }

    @GetMapping("/{id}")
    public RetVal getSectionById(@PathVariable String id) {
        EduSection section = sectionService.getSectionById(id);
        return RetVal.success().data("section", section);
    }
}

